import pygame

class ATTACK(pygame.sprite.Sprite):
    def __init__(self,position,screen_size):
        pygame.sprite.Sprite.__init__(self)
        self.width, self.height = screen_size[0], screen_size[1]
        self.roadTop = self.height//2-100
        self.imgs = []
        self.imgs1 = []
        self.imgs1.extend([pygame.image.load("1001/100101_projectile_01.png").convert_alpha(),\
                              pygame.image.load("1001/100101_projectile_02.png").convert_alpha(),\
                              pygame.image.load("1001/100101_projectile_03.png").convert_alpha(),\
                              pygame.image.load("1001/100101_projectile_04.png").convert_alpha()])
        self.imgs2 = []

        for i in range(4):
            self.imgs2.append(pygame.transform.flip(self.imgs1[i],True,False))
        #初始状态
        self.imgs = self.imgs1
        self.rect = self.imgs[0].get_rect()
        self.speed = 8
        self.active = False
        self.mask = pygame.mask.from_surface(self.imgs[0])

    def resetLeft(self,position):
        self.imgs = self.imgs1
        self.rect.right,self.rect.top = position
        self.active = True

    def resetRight(self,position):
        self.imgs = self.imgs2
        self.rect.left,self.rect.top = position
        self.active = True

    def moveLeft(self):
        self.rect.right -= self.speed
        if self.rect.right < 0:
            self.active = False

    def moveRight(self):
        self.rect.left += self.speed
        if self.rect.left > self.width:
            self.active = False

    def moveLeft(self):
        self.rect.left -=self.speed
        if self.rect.right < 0:
            self.active = False
    def moveRight(self):
        self.rect.right +=self.speed
        if self.rect.left > self.width:
            self.active = False
    def resetLeft(self,position):
        self.rect.right,self.rect.top = position
        self.active = True
    def resetRight(self,position):
        self.rect.left,self.rect.top = position
        self.active = True
